require("../css/index.less");



document.ready(function(){

  // 调用底部导航函数
  window.$utils.footerCentent()
  // 轮播图
    var mySwiper = new Swiper ('.swiper-container', {
        direction: 'horizontal', // 垂直切换选项
        loop: true, // 循环模式选项
        
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
        },
        autoplay: {
            disableOnInteraction: false,
          },
      })     
      
   

    // 从本地存储获取userid
    let userId= JSON.parse(window.localStorage.getItem("user")) .userId
    console.log(userId);
    let rankCount=document.querySelector("#rank-count")//获取排名
    let punchCount=document.querySelector("#punch-count")//获取打卡天数
    let punchToday=document.querySelector("#punch-today")//获取今日打卡
    let badgeCount=document.querySelector("#badge-count")//获取徽章数量
    
    //获取首页数据
    getIndex()
    function getIndex(){
      axios.get(`http://139.9.177.51:8099/headPageInfo?userId=${userId}`)
      .then(function(res){
      let ret=res.data  
      console.log(ret.data);
  
      if(ret.status==0){

        rankCount.textContent=ret.data.rank
        punchCount.textContent=ret.data.punchIn
        badgeCount.textContent=ret.data.insigniaNum
        punchToday.textContent=ret.data.isPunch==="false"?"今日打卡":"已打卡"

        flag=ret.data.isPunch==="false"?false:true
       }
      

     })
     .catch(function(err){
            console.log(err);
            
     })
   }
  // 今日打卡
  // 定义变量表示是否打卡
  let flag=true  //true为已打卡
  punchToday.addEventListener("click",function(){
    if(flag){
      window.$utils.toast("×","已经打卡了")

    }else{

    axios.get(`http://139.9.177.51:8099/clockIn?userId=${userId}`)
  .then(function(res){
    let ret=res.data
    console.log(ret);
    
    if(ret.status==0){
      getIndex()
    window.$utils.toast("√","打卡成功")
    }else if(ret.status==1){
    }
  })
  .catch(function(err){
    console.log(err);
  })

}
  })
  

})
 